import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import java.util.concurrent.ThreadPoolExecutor;

// 应用程序入口
public class Application {
    public static void main(String[] args) {
        // 初始化Spring注解配置的IOC容器
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext("");

        // 从容器中获取线程池和任务服务
        ThreadPoolExecutor executor = context.getBean(ThreadPoolExecutor.class);
        TaskService taskService = context.getBean(TaskService.class);

        // 提交任务到线程池执行
        executor.submit(() -> taskService.printTimeEverySecond());
        executor.submit(() -> taskService.countdownOneMinute());

        // 等待所有任务完成后关闭线程池和容器
        new Thread(() -> {
            try {
                // 等待足够长的时间让任务完成
                Thread.sleep(65000);
                executor.shutdown();
                context.close();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }).start();
    }
}
    